package com.koudai.finance.utils;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @Description: 短信验证码
 * @author: ls
 * @Date: 2020/7/11 15:24
 */
@Slf4j
public class SmsUtil {

    /**
     * @Description: 发送创瑞短信验证码
     * @author: ls
     * @Date: 2020/7/11 15:23
     */
    public static boolean sendCrMessage(String phone, String content, String sign) {
        String url = "http://api.1cloudsp.com/api/v2/single_send";
        Map<String, String> map = Maps.newHashMapWithExpectedSize(6);
        map.put("accesskey", "y3TTKQGeFOssRR7t");
        map.put("secret", "NnBLUvbi1xVUstYyX0OSfL7nBXIauz7R");
        map.put("sign", sign);
        map.put("templateId", "224443");
        map.put("mobile", phone);
        map.put("content", content);
        JSONObject jsonObject = HttpClientUtils.httpPostForm(url, map, null);
        if ("0".equals(jsonObject.getString("code"))) {
            return true;
        }
        log.error("发送普通短信失败: {}", jsonObject);
        return false;
    }

    public static void main(String[] args) {
        System.out.println(sendCrMessage("180551345", "564566","289380"));
    }
}
